/* 这是退出登录时候的hooks */
//存储登录时候的id,用户名和用户等级
import { useUserStore } from "../../stores/useUserStore"
import {onMounted} from "vue"
//导入路由
import router from "@/router"
import axios from "axios"
//导入element-plus 提示框
import { ElMessage } from "element-plus"
export const quitLogin = () => {
  const UserStore = useUserStore()
  //点击按钮退出登录退出登录
  function getQuitLogin() {
    router.push("/login")
    //清空token
    localStorage.setItem("token", "")
    getQuit()
    ElMessage({ message:"退出成功", type: "success" })
  }
  //点击发送请求修改在线状态
  function getQuit() {
    axios
      .put(`http://localhost:3000/ggusers/${UserStore.userId}`, {
        user_name: UserStore.userName,
        user_password: UserStore.userPassword,
        user_type: UserStore.userType,
        user_onlinestatus: "0",
        user_other: UserStore.userOther,
      })
      .then((res) => {
        // console.log("我是", res)
      })
    
  }
  return { getQuitLogin}
}
